﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;
using System.Collections.Specialized;
using System.Web;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;


namespace KingSite.Library.Cache.OutputCache {
    public class CacheHelperOutputCacheProvider : OutputCacheProvider {
        ICache cache = CacheHelper.GetInstance();
        public override void Initialize(string name, NameValueCollection attributes) {
            base.Initialize(name, attributes);
        }

        public override object Add(string key, object entry, DateTime utcExpiry) {
            Object obj = Get(key);
            if (obj != null) {
                return obj;
            }
            Set(key, entry, utcExpiry);
            return entry;
        }

        public override object Get(string key) {
            return cache.Get(key);
        }

        public override void Set(string key, object entry, DateTime utcExpiry) {
            DateTime now = DateTime.Now.ToUniversalTime();
            int sec = (int)(utcExpiry - now).TotalSeconds;
            cache.Add(key, entry, sec);
        }

        public override void Remove(string key) {
            cache.Remove(key);
        }

    }


}
